using UnityEngine;
using System.Collections;

public class EnemyHuntState : State<EnemyControl> 
{
    #region Singleton

    private static EnemyHuntState instance = new EnemyHuntState();
    public static EnemyHuntState Instance { get { return instance; } }
    private EnemyHuntState() { }

    #endregion

    #region State


    public override void OnEnterState(EnemyControl behaviour)
    {
    }

    public override void OnUpdateState(EnemyControl behaviour)
    {
        if (behaviour.IsTargetInAttackRange())
            behaviour.State = EnemyAttackState.Instance;
        else if (behaviour.IsObstacleInDetectionRange())
            behaviour.State = EnemyWaitState.Instance;
        else if (behaviour.IsTargetInViewRange())
        {
            if (behaviour.IsGrounded)
                behaviour.moveDirection = behaviour.transform.forward * behaviour.runSpeed;
  
            behaviour.Move();
        }
        else /* No enemy in range */
            behaviour.State = EnemyAlertState.Instance;
    }

    public override void OnFixedUpdateState(EnemyControl behaviour)
    {
    }

    public override void OnExitState(EnemyControl behaviour)
    {
        behaviour.moveDirection = Vector3.zero;
    }

    public override void OnCollisionState(EnemyControl behaviour, Collision other)
    {
    }

    public override void OnTriggerState(EnemyControl behaviour, Collider other)
    {
    }

    #endregion
}
